package nio;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;

/**
 * Created by Administrator on 2017/10/22 022.
 */
public class CharsetDemo
{
    public static void main(String[] args) throws Exception
    {
        Charset set = Charset.forName("GBK");
        CharsetDecoder decorder = set.newDecoder();
        CharsetEncoder encoder = set.newEncoder();
        CharBuffer buf = CharBuffer.allocate(8);
        buf.put('a');
        buf.put('b');
        buf.put('c');
        buf.flip();
        ByteBuffer bf = encoder.encode(buf);
        for (int i = 0; i < bf.capacity(); i++)
        {
            System.out.println(bf.get(i));
        }
        System.out.println(decorder.decode(bf));
    }
}
